package com.yoda.youdianda.vo;

import com.yoda.youdianda.domain.YddUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Objects;

/**
 * @author shawn
 * @date 2022年 11月 13日 11:47
 * 前台用户统计vo
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserCountVo {
    private Integer total;
    private Integer user_man;
    private Integer user_woman;

    public static UserCountVo init(List<YddUser> users) {
        UserCountVo vo = new UserCountVo();
        if (!Objects.isNull(users) && users.size() > 0) {
            vo.setTotal(users.size());
            Integer user_man = 0;
            Integer user_woman = 0;
            for (YddUser user : users) {
                if (user.getSex() == 0) {
                    user_man++;
                } else if (user.getSex() == 1) {
                    user_woman++;
                }
            }
            vo.setUser_man(user_man);
            vo.setUser_woman(user_woman);
        }
        return vo;
    }
}
